package com.lj.controller;

import com.github.pagehelper.PageInfo;
import com.lj.pojo.ClientProjectljKey;
import com.lj.pojo.Clientlj;
import com.lj.service.ClientProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/clientProject")
public class ClientProjectAction {
    public static final int PAGE_SIZE=5;
    @Autowired
    ClientProjectService clientProjectService;
    @RequestMapping("/selectClientProject")
    public String selectClientProject(HttpServletRequest request){
        //得到第一页数据
        PageInfo info=clientProjectService.selectClientProject(1,PAGE_SIZE);
        request.setAttribute("info",info);
        return "admin/clientProjectView";
    }
    //ajax分页翻页处理
    @ResponseBody
    @RequestMapping("/ajaxSplit")
    public void ajaxSplit(int page, HttpSession session){
        //取得当前page参数页面的数据
        PageInfo info=clientProjectService.selectClientProject(page,PAGE_SIZE);
        session.setAttribute("info",info);
    }
    @RequestMapping("/insert")
    public String insert(ClientProjectljKey clientProjectljKey){
        int num=-1;
        num=clientProjectService.insertClientProject(clientProjectljKey);
        return "redirect:/clientProject/selectClientProject.action";
    }
    @RequestMapping("/delete")
    public String delete(ClientProjectljKey clientProjectljKey){
        int nums=-1;
        nums=clientProjectService.delete(clientProjectljKey);
        return "forward:/clientProject/selectClientProject.action";
    }
    @ResponseBody
    @RequestMapping("/getClientProjectById")
    public ClientProjectljKey getClientProjectById(String clientId, HttpServletRequest request ){
        ClientProjectljKey clientProjectljKey=clientProjectService.getById(clientId);
        return clientProjectljKey;
    }
    @RequestMapping("/update")
    public String update(ClientProjectljKey clientProjectljKey){

        int nums= clientProjectService.update(clientProjectljKey);
        return "redirect:/clientProject/selectClientProject.action";
    }

}
